﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Hangjing.DBUtility;
using Hangjing.Model;

namespace Hangjing.SQLServerDAL
{
    /// <summary>
    /// 配送员修改日志
    /// </summary>
    public partial class deliverlog
    {

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(deliverlogInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into deliverlog(");
            strSql.Append("admin,optime,eventname,columntext,columnname,oldvalue,newvalue,reveint1,reveint2,revevar1,revevar2");
            strSql.Append(") values (");
            strSql.Append("@admin,@optime,@eventname,@columntext,@columnname,@oldvalue,@newvalue,@reveint1,@reveint2,@revevar1,@revevar2");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = 
			{
			    new SqlParameter("@admin", SqlDbType.VarChar,50) ,            
                new SqlParameter("@optime", SqlDbType.DateTime) ,            
                new SqlParameter("@eventname", SqlDbType.VarChar,50) ,            
                new SqlParameter("@columntext", SqlDbType.VarChar,50) ,            
                new SqlParameter("@columnname", SqlDbType.VarChar,50) ,            
                new SqlParameter("@oldvalue", SqlDbType.VarChar,512) ,            
                new SqlParameter("@newvalue", SqlDbType.VarChar,512) ,            
                new SqlParameter("@reveint1", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint2", SqlDbType.Int,4) ,            
                new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revevar2", SqlDbType.VarChar,256)             
              
            };

            parameters[0].Value = model.admin;
            parameters[1].Value = model.optime;
            parameters[2].Value = model.eventname;
            parameters[3].Value = model.columntext;
            parameters[4].Value = model.columnname;
            parameters[5].Value = model.oldvalue;
            parameters[6].Value = model.newvalue;
            parameters[7].Value = model.reveint1;
            parameters[8].Value = model.reveint2;
            parameters[9].Value = model.revevar1;
            parameters[10].Value = model.revevar2;
            return HJConvert.ToInt32(SQLHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters));
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(deliverlogInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update deliverlog set ");

            strSql.Append(" admin = @admin , ");
            strSql.Append(" optime = @optime , ");
            strSql.Append(" eventname = @eventname , ");
            strSql.Append(" columntext = @columntext , ");
            strSql.Append(" columnname = @columnname , ");
            strSql.Append(" oldvalue = @oldvalue , ");
            strSql.Append(" newvalue = @newvalue , ");
            strSql.Append(" reveint1 = @reveint1 , ");
            strSql.Append(" reveint2 = @reveint2 , ");
            strSql.Append(" revevar1 = @revevar1 , ");
            strSql.Append(" revevar2 = @revevar2  ");
            strSql.Append(" where lId=@lId ");

            SqlParameter[] parameters = 
			{
			    new SqlParameter("@lId", SqlDbType.Int,4) ,            
                new SqlParameter("@admin", SqlDbType.VarChar,50) ,            
                new SqlParameter("@optime", SqlDbType.DateTime) ,            
                new SqlParameter("@eventname", SqlDbType.VarChar,50) ,            
                new SqlParameter("@columntext", SqlDbType.VarChar,50) ,            
                new SqlParameter("@columnname", SqlDbType.VarChar,50) ,            
                new SqlParameter("@oldvalue", SqlDbType.VarChar,512) ,            
                new SqlParameter("@newvalue", SqlDbType.VarChar,512) ,            
                new SqlParameter("@reveint1", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint2", SqlDbType.Int,4) ,            
                new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revevar2", SqlDbType.VarChar,256)             
              
            };

            parameters[0].Value = model.lId;
            parameters[1].Value = model.admin;
            parameters[2].Value = model.optime;
            parameters[3].Value = model.eventname;
            parameters[4].Value = model.columntext;
            parameters[5].Value = model.columnname;
            parameters[6].Value = model.oldvalue;
            parameters[7].Value = model.newvalue;
            parameters[8].Value = model.reveint1;
            parameters[9].Value = model.reveint2;
            parameters[10].Value = model.revevar1;
            parameters[11].Value = model.revevar2;
            return SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }


        /// <summary>
        /// 获取记录所有字段
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <param>lId</param>
        /// <returns>deliverlogInfo</returns>
        public deliverlogInfo GetModel(int lId)
        {
            string sql = "select lId,admin,optime,eventname,columntext,columnname,oldvalue,newvalue,reveint1,reveint2,revevar1,revevar2 from deliverlog where  lId = @lId";
            SqlParameter parameter = new SqlParameter("@lId", SqlDbType.Int, 4);
            parameter.Value = lId;
            deliverlogInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new deliverlogInfo();
                    model.lId = HJConvert.ToInt32(dr["lId"]);
                    model.admin = HJConvert.ToString(dr["admin"]);
                    model.optime = HJConvert.ToDateTime(dr["optime"]);
                    model.eventname = HJConvert.ToString(dr["eventname"]);
                    model.columntext = HJConvert.ToString(dr["columntext"]);
                    model.columnname = HJConvert.ToString(dr["columnname"]);
                    model.oldvalue = HJConvert.ToString(dr["oldvalue"]);
                    model.newvalue = HJConvert.ToString(dr["newvalue"]);
                    model.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    model.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得总记录数
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int GetCount(string strWhere)
        {
            return (int)SQLHelper.ExecuteScalar(CommandType.StoredProcedure, "pagecount", new SqlParameter("@tblName", "deliverlog"), new SqlParameter("@strWhere", strWhere));
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagesize">页尺寸</param>
        /// <param name="pageindex">页索引</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderName">排序字段</param>
        /// <param name="orderType">排序类型，1为降序，0为升序</param>
        /// <returns>图书列表</returns>
        ///此代码由杭景科技代码内部生成器自动生成
        public IList<deliverlogInfo> GetList(int pagesize, int pageindex, string strWhere, string orderName, int orderType)
        {
            IList<deliverlogInfo> infos = new List<deliverlogInfo>();
            SqlParameter[] parameters = 
			{
				new SqlParameter("@tblName", SqlDbType.VarChar,255),
				new SqlParameter("@strGetFields", SqlDbType.VarChar,1000),
				new SqlParameter("@primary", SqlDbType.VarChar,255),
				new SqlParameter("@orderName", SqlDbType.VarChar,255),
				new SqlParameter("@PageSize", SqlDbType.Int),
				new SqlParameter("@PageIndex", SqlDbType.Int),
				new SqlParameter("@OrderType", SqlDbType.Bit),
				new SqlParameter("@strWhere", SqlDbType.VarChar,1500)
			};
            parameters[0].Value = "deliverlog";
            parameters[1].Value = "lId,admin,optime,eventname,columntext,columnname,oldvalue,newvalue,reveint1,reveint2,revevar1,revevar2";
            parameters[2].Value = "lId";
            parameters[3].Value = orderName;
            parameters[4].Value = pagesize;
            parameters[5].Value = pageindex;
            parameters[6].Value = orderType;
            parameters[7].Value = strWhere;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.StoredProcedure, "pageselectpri", parameters))
            {
                while (dr.Read())
                {
                    deliverlogInfo info = new deliverlogInfo();
                    info.lId = HJConvert.ToInt32(dr["lId"]);
                    info.admin = HJConvert.ToString(dr["admin"]);
                    info.optime = HJConvert.ToDateTime(dr["optime"]);
                    info.eventname = HJConvert.ToString(dr["eventname"]);
                    info.columntext = HJConvert.ToString(dr["columntext"]);
                    info.columnname = HJConvert.ToString(dr["columnname"]);
                    info.oldvalue = HJConvert.ToString(dr["oldvalue"]);
                    info.newvalue = HJConvert.ToString(dr["newvalue"]);
                    info.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    info.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    info.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    info.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    infos.Add(info);
                }
            }
            return infos;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="Id"></param>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <returns></returns>
        public int Deldeliverlog(int Id)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from deliverlog where lId=@lId");
            SqlParameter[] Para = 
			{
				new SqlParameter("@lId",SqlDbType.Int)
			};
            Para[0].Value = Id;

            return SQLHelper.ExecuteNonQuery(CommandType.Text, str.ToString(), Para);
        }


        /// <summary>
        /// 批量删除记录
        /// </summary>
        /// <param name="IdList"></param>
        /// <returns></returns>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int DelList(string IdList)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from deliverlog where lId in ({0})");

            return SQLHelper.ExecuteNonQuery(CommandType.Text, string.Format(str.ToString(), IdList), null);
        }



    }
}

